package com.smec.moblie.adapter;

import android.content.Context;
import android.text.Layout;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.smec.moblie.R;
import com.smec.moblie.bean.TechnicalNoticeBean;
import com.smec.moblie.control.PublicControl;
import com.smec.moblie.util.UIUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by sunyubo on 2017/12/4.
 */

public class TechnicalNoticeAllListAdapter extends BaseAdapter {
    private List<TechnicalNoticeBean> technicalNoticeBeanList;
    private LayoutInflater inflater;
    private Context context;

    public TechnicalNoticeAllListAdapter(Context context) {
        inflater = LayoutInflater.from(context);
        technicalNoticeBeanList = new ArrayList<>();
        this.context = context;
    }

    public void setList(List<TechnicalNoticeBean> technicalNoticeBeanList) {
        this.technicalNoticeBeanList = technicalNoticeBeanList;
    }

    @Override
    public int getCount() {
        return technicalNoticeBeanList.size();
    }

    @Override
    public TechnicalNoticeBean getItem(int position) {
        return technicalNoticeBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        if (convertView == null) {
            view = inflater.inflate(R.layout.adapter_technical_notice_all_list, null);
        } else {
            view = convertView;
        }
        TextView textViewEleContractNo = (TextView) view.findViewById(R.id.textViewEleContractNo);
        TextView textViewCustomerName = (TextView) view.findViewById(R.id.textViewCustomerName);
        TextView textViewNoticeNum = (TextView) view.findViewById(R.id.textViewNoticeNum);
        TextView textViewAddress = (TextView) view.findViewById(R.id.textViewAddress);
        TextView textViewRequireCompleteDate = (TextView) view.findViewById(R.id.textViewRequireCompleteDate);
        TextView textViewCompleteDate = (TextView) view.findViewById(R.id.textViewCompleteDate);
        TextView textViewEleNo = (TextView) view.findViewById(R.id.textViewEleNo);
        TextView textViewTitle = (TextView) view.findViewById(R.id.textViewTitle);
        View view1=view.findViewById(R.id.layout_line);
        RelativeLayout relativeLayout= (RelativeLayout) view.findViewById(R.id.ll_time);
        LinearLayout layoutBack = (LinearLayout) view.findViewById(R.id.layoutBack);
        LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.ll_actual);

        if (position == 0) {
            PublicControl.setMargins(layoutBack, UIUtil.dip2px(context, 10), UIUtil.dip2px(context, 10), UIUtil.dip2px(context, 10), UIUtil.dip2px(context, 10));
        } else {
            PublicControl.setMargins(layoutBack, UIUtil.dip2px(context, 10), 0, UIUtil.dip2px(context, 10), UIUtil.dip2px(context, 10));
        }

        TechnicalNoticeBean technicalNoticeBean = technicalNoticeBeanList.get(position);
        textViewEleContractNo.setText(technicalNoticeBean.getEleContractNo());
        textViewCustomerName.setText(technicalNoticeBean.getCustomerName());
        textViewNoticeNum.setText(technicalNoticeBean.getNoticeNum());
        textViewAddress.setText(technicalNoticeBean.getAddress());
        textViewRequireCompleteDate.setText(technicalNoticeBean.getRequireCompleteDate());
        textViewCompleteDate.setText(technicalNoticeBean.getCompleteDate());
        textViewEleNo.setText(technicalNoticeBean.getEleNo());
        if(!TextUtils.isEmpty(technicalNoticeBean.getTitle())){
            textViewTitle.setText(technicalNoticeBean.getTitle());
//            textViewTitle.setText("任务标题任务标题任务标题");
        }
        if(technicalNoticeBean.getStatus().equals("UNCOMPLETED")){
            linearLayout.setVisibility(View.GONE);
        }else {
            linearLayout.setVisibility(View.VISIBLE);
        }
        return view;
    }
}
